********************************************************************************
* ELECTORAL REPERCUSSIONS OF A PANDEMIC:  EVIDENCE FROM THE 2009 H1N1 OUTBREAK *
********************************************************************************

// THIS FILE REPLICATES TABLES C2 AND C3 IN APPENDIX C OF "ELECTORAL 
// REPERCUSSIONS OF A PANDEMIC: EVIDENCE FROM THE 2009 H1N1 OUTBREAK" BY
// EMILIO GUTIÉRREZ, JAAKKO MERILÄINEN, AND ADRIÁN RUBLI

global data "XXX" // Insert data directory here
global output "XXX" // Insert output directory here

* Open data

use "$data/GMR_district_level_data.dta", clear

********************************************************************************

gen post=0
replace post=1 if year!=2006

* Table C2

preserve

keep if year==2006 | year==2009

est clear

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw=total_votos] if year==2006 | year==2009, absorb(id i.estado#i.year) cluster(id)
estadd scalar N1 = e(N)
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"

restore

preserve

keep if year==2006 | year==2009

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw=total_votos] if year==2006 | year==2009 , absorb(id i.estado#i.year) cluster(id)
estadd scalar N1 = e(N)
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.


eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw=total_votos], absorb(id i.estado#i.year) cluster(id)
estadd scalar N1 = e(N)
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"

restore

preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw=total_votos], absorb(id i.estado#i.year) cluster(id)
estadd scalar N1 = e(N)
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"

restore

esttab est*  using "$output/tableC2.tex", replace noomitted nobaselevels booktabs  mlabels(none) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	mgroups("2006-2009" "2006-2012", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	b(%9.3f) se(%9.3f) stats(N1 N3 district stateyear, labels("Number of observations" "Number of clusters" "District FE" "State-year FE") ///
	fmt(0 0 0)) keep(1.post#c.change_ari 1.post#c.change_ari_z) ///
	coeflabels(1.post#c.change_ari "1[Year $\geq$ 2009] $\times$ Excess ARI cases (1000s)" ///
	1.post#c.change_ari_z "1[Year $\geq$ 2009] $\times$ Excess ARI cases (z-score)") ///
	order(1.post#c.change_ari 1.post#c.change_ari_z) ///
	nodepvars nomtitle prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular})
	
********************************************************************************

* Table C3

preserve

keep if year==2006 | year==2009

est clear

eststo: reghdfe PAN_voteshare 1.post##c.change_ari if year==2006 | year==2009, absorb(id i.estado#i.year) cluster(id)
estadd scalar N1 = e(N)
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"

restore

preserve

keep if year==2006 | year==2009

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z if year==2006 | year==2009, absorb(id i.estado#i.year) cluster(id)
estadd scalar N1 = e(N)
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.


eststo: reghdfe PAN_voteshare 1.post##c.change_ari, absorb(id i.estado#i.year) cluster(id)
estadd scalar N1 = e(N)
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"

restore

preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z, absorb(id i.estado#i.year) cluster(id)
estadd scalar N1 = e(N)
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"

restore

esttab est*  using "$output/tableC3.tex", replace noomitted nobaselevels booktabs  mlabels(none) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	mgroups("2006-2009" "2006-2012", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	b(%9.3f) se(%9.3f) stats(N1 N3 district stateyear, labels("Number of observations" "Number of clusters" "District FE" "State-year FE") ///
	fmt(0 0 0)) keep(1.post#c.change_ari 1.post#c.change_ari_z) ///
	coeflabels(1.post#c.change_ari "1[Year $\geq$ 2009] $\times$ Excess ARI cases (1000s)" ///
	1.post#c.change_ari_z "1[Year $\geq$ 2009] $\times$ Excess ARI cases (z-score)") ///
	order(1.post#c.change_ari 1.post#c.change_ari_z) ///
	nodepvars nomtitle prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular})
